<?php
namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use frontend\models\Advertiser_user;
use frontend\models\Advertiser_info;

class BusinessloginController extends Controller{
	//禁用yii框架自带模板
	public $layout = false;
	//登录页面
	public function actionIndex(){
		return $this->render('index');
	}
	//注册页面
	public function actionRegister(){
		return $this->render('register');
	}
	public function actionLoginajax(){
		$session = Yii::$app->session;
		$advertiser = new Advertiser_user;
		$account = Yii::$app->request->get('account');
		$pwd = Yii::$app->request->get('pwd');
		$data = $advertiser->find()->where("account = '$account' and pwd ='$pwd'")->one();
		if($data!=''){
			$session['business'] = [
			    'account' => $account,
			    'business_id' => $data['id'],
			];
			echo '1';
		}else{
			echo '2';
		}
	}
	//ajax注册处理
	public function actionAddajax(){
		$session = Yii::$app->session;
		$advertiser = new Advertiser_user;
		$account = Yii::$app->request->get('account');
		$pwd = Yii::$app->request->get('pwd');
		$advertiser->account = $account;
		$advertiser->pwd = $pwd;
		if($advertiser->insert()){
			// $session->set('business',$account);
			$session['business'] = [
			    'account' => $account,
			    'business_id' => $advertiser->id,
			];
			$advertiser_info = new Advertiser_info;
			$advertiser_info->advertiser_id = $advertiser->id;
			$advertiser_info->addtime = time();
			if($advertiser_info->insert()){
			echo '1';
			}
		}

	}
	public function actionOneajax(){
		$account = Yii::$app->request->get('account');
		$advertiser = new Advertiser_user;
		$data =$advertiser->find()->where("account =  '$account'")->one();
		if($data==''){
			echo '1';
		}else{
			echo '2';
		}
	}
}

?>